package org.eae.eldf.dao.base.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.eae.eldf.dao.base.IPortalCompanyUserDao;
import org.eae.eldf.dto.base.BaseLanguageDto;
import org.eae.eldf.dto.base.PortalCompanyUserBean;
import org.eae.eldf.dto.base.PortalCompanyUserQueryDto;
import org.eae.eldf.entity.company.PortalCompanyUser;
import org.eae.eldf.framework.dao.JdbcDaoImpl;
import org.eae.eldf.framework.pager.Pagination;
import org.springframework.stereotype.Repository;
@Repository
public class PortalCompanyUserDaoImpl extends JdbcDaoImpl implements IPortalCompanyUserDao{

	@Override
	public Pagination<PortalCompanyUserBean> queryListBaseCompanyInfo(Pagination<PortalCompanyUserBean> pager,
			PortalCompanyUserQueryDto portalCompanyUserQueryDto) {
		StringBuffer sql= new StringBuffer("select JSON_UNQUOTE(json_extract (c.company_name, '$.zh_CN')) as companyName,")
				.append("u.username,u.company_code as companyCode,u.email,u.phone,u.real_name as realName ")
				.append("from portal_company_user u ")
				.append("left join base_company_info c on u.company_code = c.company_code where u.is_delete=0 ");
		List<Object> params= new ArrayList<Object>();
		if(null!=portalCompanyUserQueryDto){
			if(StringUtils.isNotBlank(portalCompanyUserQueryDto.getCompanyCode())){
				sql.append("and u.company_code=?");
				params.add(portalCompanyUserQueryDto.getCompanyCode());
			}
			if(StringUtils.isNotBlank(portalCompanyUserQueryDto.getUsername())){
				sql.append("and u.username like ?");
				params.add("%"+portalCompanyUserQueryDto.getUsername()+"%");
			}
		}
		
		return this.queryListByPage(pager, sql.toString(),params,PortalCompanyUserBean.class);
	}

}
